#include<graphics.h>
#include<windows.h>
#include<math.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include<stdio.h>

#define width 640
#define height 480

SYSTEMTIME start;

IMAGE img[3][3];
IMAGE c;
IMAGE masks_2[10];
IMAGE dot;
IMAGE sc[3];
IMAGE k;
int i, j, op = 1;
int brick_left, brick_right, brick_top, brick_bottom;
void time();
void drawinit();
void control();
void tishi();
void shitong();
void main(){

	initgraph(width, height);
	shitong();
	drawinit();
	control();
	closegraph();
	_getch();

}
void shitong()
{
	GetLocalTime(&start);
	loadimage(&img[0][0], _T("./1.jpg"));
	Resize(&img[0][0], 192, 144);
	for (j = 0; j<10; j++){
		for (i = 0; i<10; i++){
			brick_left = i * 64;
			brick_right = brick_left + 64;
			brick_top = 0 + j * 48;
			brick_bottom = (j + 1) * 48;
			fillrectangle(brick_left, brick_top, brick_right, brick_bottom);

		}
	}tishi();
	putimage(0, 0, &img[0][0]);
	for (i = 0; i<3; i++){
		for (j = 0; j<3; j++){
			getimage(&img[j][i], j * 64, i * 48, 64, 48);
		}
	}
	for (i = 0; i<3; i++){
		for (j = 0; j<3; j++){
			putimage((4 + j) * 64, (5 + i) * 48, &img[i][j]);
		}
	}
	line(5 * 64, 5 * 48, 5 * 64, 8 * 48);
	line(6 * 64, 5 * 48, 6 * 64, 8 * 48);
	line(4 * 64, 6 * 48, 7 * 64, 6 * 48);
	line(4 * 64, 7 * 48, 7 * 64, 7 * 48);
}
void time(){
	int t1, t2;
	int c, d;
	int a, b;
	int sum;

	SYSTEMTIME ti;
	sum = 0;
	GetLocalTime(&ti);
	sum += ti.wHour - start.wHour;
	sum *= 60;
	sum += ti.wMinute - start.wMinute;

	sum *= 60;
	sum += ti.wSecond - start.wSecond;
	c = 0;
	d = 0;
	t1 = sum;
	t2 = sum / 60;
	while (c != 2)
	{
		if (c == 0)
		{
			t1 = sum % 60;
		}
		a = t1 % 10;
		putimage(380 - 32 * c, 400, &masks_2[a]);
		t1 = t1 / 10;
		c++;
	}
	while (d != 2)
	{
		b = t2 % 10;
		putimage(300 - 32 * d, 400, &masks_2[b]);
		t2 = t2 / 10;
		d++;
	}
	if (ti.wMinute - start.wMinute >= 10){
		putimage(0, 0, &k);
	}
}
void drawinit(){
	loadimage(&masks_2[0], _T("./images/t0.bmp"));
	loadimage(&masks_2[1], _T("./images/t1.bmp"));
	loadimage(&masks_2[2], _T("./images/t2.bmp"));
	loadimage(&masks_2[3], _T("./images/t3.bmp"));
	loadimage(&masks_2[4], _T("./images/t4.bmp"));
	loadimage(&masks_2[5], _T("./images/t5.bmp"));
	loadimage(&masks_2[6], _T("./images/t6.bmp"));
	loadimage(&masks_2[7], _T("./images/t7.bmp"));
	loadimage(&masks_2[8], _T("./images/t8.bmp"));
	loadimage(&masks_2[9], _T("./images/t9.bmp"));
	loadimage(&k, _T("./images/10.jpg"));
	Resize(&k, 640, 480);
	loadimage(&dot, _T("./images/dot.bmp"));
	putimage(335, 410, &dot);
	putimage(335, 435, &dot);
	return;
}
void control()
{	while (1)
	{
	MOUSEMSG m;
	int j;
	while (1){
		if (MouseHit()){
			m = GetMouseMsg();
			if (m.mkLButton){
				if (m.y>(48 * 5 && m.y<48 * 6)){
					for (j = 0; j<3; j++){
						if (m.x>64 * (j + 4) && m.x<(j + 4 + 1) * 64){
							sc[0] = img[0][j];
						}
					}
				}
				if (m.y>48 * 6 && m.y<48 * 7){
					for (int j = 0; j<3; j++){
						if (m.x>64 * (j + 4) && m.x<(j + 4 + 1) * 64){
							sc[0] = img[1][j];

						}

					}
				}
				if (m.y>48 * 7 && m.y<48 * 8){
					for (j = 0; j<3; j++){
						if (m.x>64 * (j + 4) && m.x<(j + 4 + 1) * 64){
							sc[0] = img[2][j];

						}
					}
				}

				if (m.y>48 * 0 && m.y<48 * 1){
					for (j = 7; j<10; j++){
						if (m.x>64 * j&&m.x<(j + 1) * 64){
							putimage(64 * j, 48 * 0, &sc[0]);

						}

					}
				}
				if (m.y>48 * 1 && m.y<48 * 2){
					for (j = 7; j<10; j++){
						if (m.x>64 * j&&m.x<(j + 1) * 64){
							putimage(64 * j, 48 * 1, &sc[0]);

						}

					}
				}
				if (m.y>48 * 2 && m.y<48 * 3){
					for (j = 7; j<10; j++){
						if (m.x>64 * j&&m.x<(j + 1) * 64){
							putimage(64 * j, 48 * 2, &sc[0]);

						}

					}
				}

			}
		}
		time();
	}
}
}
void tishi(){
	setcolor(BLACK);
	line(7 * 64, 1 * 48, 10 * 64, 1 * 48);
	line(7 * 64, 2 * 48, 10 * 64, 2 * 48);
	line(8 * 64, 0 * 48, 8 * 64, 3 * 48);
	line(9 * 64, 0 * 48, 9 * 64, 3 * 48);
	line(7 * 64, 0 * 48, 10 * 64, 0 * 48);
	line(7 * 64, 3 * 48, 10 * 64, 3 * 48);
	line(7 * 64, 0 * 48, 7 * 64, 3 * 48);
}